﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FDEE.Model
{
    class CPTM1S : CPTMBase
    {
        Dictionary<double, List<int>> dic = new Dictionary<double, List<int>>();
        Dictionary<double, List<int>> addDic = new Dictionary<double, List<int>>();
        bool isAdd = false;
        internal CPTM1S(string typeName, string pierNumber, eColumnType ct, eSubType st,
            int ww, int ll, int hh, int rr, double up, double low,
            eDB mainDB, string listCString = "", string listAddCString = "")
            : base(typeName, pierNumber, ct, st, ww, ll, hh, rr, up, low, mainDB)
        {
            if (st == eSubType.D)
            {
                listCString = "{(4,8)|248};{(3,9)|225};{(5,7)|135};{(2,10)|125}";
                listAddCString = "{(3,9)|225};{(5,7)|135};{(2,10)|125}";
                List<string> listC = listCString.Split(';').ToList();
                List<string> listAddC = listAddCString.Split(';').ToList();
                Dictionary<double, List<int>> dicV = new Dictionary<double, List<int>>();

                foreach (var item in listC)
                {
                    string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                    double vk = double.Parse(values[1]);
                    string[] vs = values[0].Split(',');
                    List<int> v = new List<int>();
                    foreach (var vl in vs)
                    {
                        v.Add(int.Parse(vl));
                    }
                    if (!dicV.Keys.Contains(vk))
                        dicV.Add(vk, v);
                    //dic = dicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    dic = dicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                }
                Dictionary<double, List<int>> adddicV = new Dictionary<double, List<int>>();
                foreach (var item in listAddC)
                {
                    string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                    double vk = double.Parse(values[1]);
                    string[] vs = values[0].Split(',');
                    List<int> v = new List<int>();
                    foreach (var vl in vs)
                    {
                        v.Add(int.Parse(vl));
                    }
                    if (!adddicV.Keys.Contains(vk))
                        adddicV.Add(vk, v);
                    //addDic = adddicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    addDic = adddicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                }
            }
            if (st == eSubType.C)
            {
                listCString = "{(3,9)|225};(4,8)|248};{(5,7)|135}";
                listAddCString = "{(3,9)|225};{(5,7)|135}";
                //listCString = "{{(2,10)|125};{(5,7)|135};{(3,9)|225};(4,8)|248}";
                //listAddCString = "{(5,7)|135};{(3,9)|225}";
                List<string> listC = listCString.Split(';').ToList();
                List<string> listAddC = listAddCString.Split(';').ToList();
                Dictionary<double, List<int>> dicV = new Dictionary<double, List<int>>();

                foreach (var item in listC)
                {
                    string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                    double vk = double.Parse(values[1]);
                    string[] vs = values[0].Split(',');
                    List<int> v = new List<int>();
                    foreach (var vl in vs)
                    {
                        v.Add(int.Parse(vl));
                    }
                    if (!dicV.Keys.Contains(vk))
                        dicV.Add(vk, v);
                    //dic = dicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    //dic = dicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    dic = dicV;
                }
                Dictionary<double, List<int>> adddicV = new Dictionary<double, List<int>>();
                foreach (var item in listAddC)
                {
                    string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                    double vk = double.Parse(values[1]);
                    string[] vs = values[0].Split(',');
                    List<int> v = new List<int>();
                    foreach (var vl in vs)
                    {
                        v.Add(int.Parse(vl));
                    }
                    if (!adddicV.Keys.Contains(vk))
                        adddicV.Add(vk, v);
                    //addDic = adddicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    //addDic = adddicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    addDic = adddicV;
                }
            }
            else if (st == eSubType.B)
            {
                listCString = "{(3,9)|225};{(4,8)|248};{(5,7)|135}";
                listAddCString = "{(2,10)|125};{(3,9)|225}";
                List<string> listC = listCString.Split(';').ToList();
                List<string> listAddC = listAddCString.Split(';').ToList();
                Dictionary<double, List<int>> dicV = new Dictionary<double, List<int>>();

                foreach (var item in listC)
                {
                    string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                    double vk = double.Parse(values[1]);
                    string[] vs = values[0].Split(',');
                    List<int> v = new List<int>();
                    foreach (var vl in vs)
                    {
                        v.Add(int.Parse(vl));
                    }
                    if (!dicV.Keys.Contains(vk))
                        dicV.Add(vk, v);
                    //dic = dicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    //dic = dicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    dic = dicV;
                }
                Dictionary<double, List<int>> adddicV = new Dictionary<double, List<int>>();
                foreach (var item in listAddC)
                {
                    string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                    double vk = double.Parse(values[1]);
                    string[] vs = values[0].Split(',');
                    List<int> v = new List<int>();
                    foreach (var vl in vs)
                    {
                        v.Add(int.Parse(vl));
                    }
                    if (!adddicV.Keys.Contains(vk))
                        adddicV.Add(vk, v);
                    //addDic = adddicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    //addDic = adddicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    addDic = adddicV;
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(listCString))
                {
                    List<string> listC = listCString.Split(';').ToList();
                    List<string> listAddC = listAddCString.Split(';').ToList();
                    Dictionary<double, List<int>> dicV = new Dictionary<double, List<int>>();

                    foreach (var item in listC)
                    {
                        string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                        double vk = double.Parse(values[1]);
                        string[] vs = values[0].Split(',');
                        List<int> v = new List<int>();
                        foreach (var vl in vs)
                        {
                            v.Add(int.Parse(vl));
                        }
                        if (!dicV.Keys.Contains(vk))
                            dicV.Add(vk, v);
                        dic = dicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                        //dic = dicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    }
                    Dictionary<double, List<int>> adddicV = new Dictionary<double, List<int>>();
                    foreach (var item in listAddC)
                    {
                        string[] values = item.Replace("{", "").Replace("}", "").Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split('|');
                        double vk = double.Parse(values[1]);
                        string[] vs = values[0].Split(',');
                        List<int> v = new List<int>();
                        foreach (var vl in vs)
                        {
                            v.Add(int.Parse(vl));
                        }
                        if (!adddicV.Keys.Contains(vk))
                            adddicV.Add(vk, v);
                        addDic = adddicV.OrderByDescending(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                        //addDic = adddicV.OrderBy(p => p.Key).ToDictionary(p => p.Key, o => o.Value);
                    }
                }
            }
        }

        public override void SetRebarDistribute()
        {
            double d1, d2;
            double d1r, d2r;
            switch (SubType)
            {
                case eSubType.A:
                case eSubType.B:
                    d1r = Math.Round((Length - Radius * 2) / 12.0,0);
                    d2r = Math.Round((Width - Radius * 2) / 7.0,0);
                    d1 = (Length - Radius * 2) / 12;
                    d2 = (Width - Radius * 2) / 7;
                    if (d1r > d1)
                        isAdd = true;
                    //A截面参数
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 12);                 
                    AddLBarDistribute = new RebarTendonDistribute();
                    AddLBarDistribute.Location = MainLBarDistribute.Delete(new List<int>() { 0, 2, 4, 5, 7, 8, 10,12 });
                    MainWBarDistribute = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistribute = new RebarTendonDistribute();
                    AddWBarDistribute.Location = MainWBarDistribute.Delete(new List<int>() { 0, 2,  5, 7 });
                    //B截面参数
                    MainLBarDistributeB = new RebarTendonDistribute();
                    MainLBarDistributeB.Location = MainLBarDistribute.Delete(new List<int>() { 2, 6, 10 });
                    AddLBarDistributeB = new RebarTendonDistribute();
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeB = new RebarTendonDistribute();
                    //C截面参数
                    MainLBarDistributeC = new RebarTendonDistribute();
                    MainLBarDistributeC.Location = MainLBarDistribute.Delete(new List<int>() { 2, 6, 10 });
                    AddLBarDistributeC = new RebarTendonDistribute();
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeC = new RebarTendonDistribute();
                    break;
                case eSubType.C:
                    d1r = Math.Round((Length - Radius * 2) / 12.0, 0);
                    d2r = Math.Round((Width - Radius * 2) / 7.0, 0);
                    d1 = (Length - Radius * 2) / 12;
                    d2 = (Width - Radius * 2) / 7;
                    if (d1r > d1)
                        isAdd = true;
                    //A截面参数
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 12);
                    AddLBarDistribute = new RebarTendonDistribute();
                    AddLBarDistribute.Location = MainLBarDistribute.Delete(new List<int>() { 0, 2, 4, 6, 8, 10, 12 });
                    MainWBarDistribute = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistribute = new RebarTendonDistribute();
                    AddWBarDistribute.Location = MainWBarDistribute.Delete(new List<int>() { 0, 7 });
                    //B截面参数
                    MainLBarDistributeB = new RebarTendonDistribute();
                    MainLBarDistributeB.Location = MainLBarDistribute.Delete(new List<int>() { 2, 6, 10 });
                    AddLBarDistributeB = new RebarTendonDistribute();
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeB = new RebarTendonDistribute();
                    //C截面参数
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 12);                   
                    AddLBarDistributeC = new RebarTendonDistribute();
                    AddLBarDistributeC.Location = MainLBarDistribute.Delete(new List<int>() { 0, 2, 3,4,5, 6,7, 8,9, 10, 12 });
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 7);
                    AddWBarDistributeC = new RebarTendonDistribute();
                    break;
                case eSubType.D:
                    //d1 = Math.Round((Length - Radius * 2) / 12.0,0);
                    //d2 = Math.Round((Width - Radius * 2) / 9.0,0);
                    d1r = Math.Round((Length - Radius * 2) / 12.0, 0);
                    d2r = Math.Round((Width - Radius * 2) / 9.0, 0);
                    d1 = (Length - Radius * 2) / 12;
                    d2 = (Width - Radius * 2) / 9;
                    if (d1r > d1)
                        isAdd = true;
                    //A截面参数
                    MainLBarDistribute = new RebarTendonDistribute(32, d1, 12);
                    AddLBarDistribute = new RebarTendonDistribute();
                    AddLBarDistribute.Location = MainLBarDistribute.Delete(new List<int>() { 0,  4,  8,  12 });
                    MainWBarDistribute = new RebarTendonDistribute(32, d2, 9);
                    AddWBarDistribute = new RebarTendonDistribute();
                    AddWBarDistribute.Location = MainWBarDistribute.Delete(new List<int>() { 0, 2,4,5,7,9});
                    //B截面参数
                    MainLBarDistributeB = new RebarTendonDistribute(32, d1, 12);                    
                    AddLBarDistributeB = new RebarTendonDistribute();                  
                    MainWBarDistributeB = new RebarTendonDistribute(32, d2, 9);
                    AddWBarDistributeB = new RebarTendonDistribute();
                    //C截面参数
                    MainLBarDistributeC = new RebarTendonDistribute(32, d1, 12);
                    AddLBarDistributeC = new RebarTendonDistribute();
                    AddLBarDistributeC.Location = MainLBarDistribute.Delete(new List<int>() { 0,2,4,6,8,10,12});
                    MainWBarDistributeC = new RebarTendonDistribute(32, d2, 9);
                    AddWBarDistributeC = new RebarTendonDistribute();
                    AddWBarDistributeC.Location = MainWBarDistributeC.Delete(new List<int>() { 0,2,4,5,7,9});
                    break;
            }
        }

        public override void SetRebarList()
        {
            #region 0-箍筋
            int npts = GetStirrupNum();
            if(isAdd)
               RebarList.Add(new MORebarRecord(1, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[1] * -2 + 32+MainWBarDistribute.Location.Count-2*1-1));
            else
                RebarList.Add(new MORebarRecord(1, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[1] * -2 + 32));
            //RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[3] * -2 + 32));
            int tmpn = 3;
            int tmp2 = 3;
            switch (SubType)
            {
                case eSubType.A:
                case eSubType.B:
                    tmpn = 3;
                    tmp2 = 3;
                    break;
                case eSubType.C:
                    tmpn = 3;
                    tmp2 = 3;
                    break;
                case eSubType.D:                
                    tmpn = 3;
                    tmp2 = 3;
                    break;
            }
            if (isAdd)
                RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[tmp2] * -2 + 32+ MainWBarDistribute.Location.Count-2* tmp2-1));
            else
                RebarList.Add(new MORebarRecord(2, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, (int)MainWBarDistribute.Location[tmp2] * -2 + 32));

            if (isAdd)
                RebarList.Add(new MORebarRecord(3, 0, "", eDB.DB12, npts * 3, eShapeType.MO, Width - 100 - 24, MainLBarDistribute.Distance(1, tmpn) + 32+ tmpn-1));
            else
                RebarList.Add(new MORebarRecord(3, 0, "", eDB.DB12, npts * 3, eShapeType.MO, Width - 100 - 24, MainLBarDistribute.Distance(1, tmpn) + 32));
            RebarList.Add(new MORebarRecord(4, 0, "", eDB.DB12, npts, eShapeType.MO, Length - 100 - 24, Width - 100 - 24, 138));
            #endregion

            #region 1-获取承台尺寸
            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            int FTWidth = theFooting.Width;
            int FTLen = theFooting.Length;
            int db = (int)MainRebarDB;
            #endregion

            #region 2-起步筋
            int NumOFout = 0;// 外向起步筋
            int NumMainAll = MainWBarDistributeC.Location.Count * 2 + MainLBarDistributeC.Location.Count * 2 + 4;
            if ((FTWidth - Width) * 0.5 >= 600)
            {
                NumOFout += MainLBarDistributeC.Location.Count * 2;
            }
            if ((FTLen - Length) * 0.5 >= 600)
            {
                NumOFout += MainWBarDistributeC.Location.Count * 2 + 4;
            }
            //int NumAdd = AddLBarDistributeC.Location.Count * 2 + AddWBarDistributeC.Location.Count * 2;
            //5.1a为内侧起步筋，所有加强筋为内侧起步；
            //RebarList.Add(new MHXRebarRecord(5, 1, "a", MainRebarDB, true, NumMainAll - NumOFout + NumAdd, eShapeType.MHX));

            ////5.1b为外侧起步筋；
            //if (NumOFout != 0)
            //{
            //    RebarList.Add(new MHXRebarRecord(5, 1, "b", MainRebarDB, false, NumOFout, eShapeType.MHXe));
            //}
            string no5 = "a";
            if (NumMainAll - NumOFout  > 0)
            {
                //RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, true, NumMainAll - NumOFout, eShapeType.MHX));
                if (SubType == eSubType.C)
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, true, 20, eShapeType.MHX, 12000));
                else
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, true, NumMainAll - NumOFout, eShapeType.MHX));

                no5 = "b";
            }
            //5.1b为外侧起步筋；
            if (NumOFout != 0)
            {
                if (no5 == "a")
                    no5 = "";
                //RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, false, NumOFout, eShapeType.MHXe));
                if (SubType == eSubType.C)
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, false, 20, eShapeType.MHXe, 12000));
                else
                    RebarList.Add(new MHXRebarRecord(5, 1, no5, MainRebarDB, false, NumOFout, eShapeType.MHXe));
            }
            #endregion


            #region 3-锚固筋
            if (SubType == eSubType.D)
            {
                SetTypeDValue();
            }
            else if (SubType == eSubType.C)
            {
                SetTypeCValue();
            }
            else
            {
                SetTypeBValue();
            }
            #endregion


        }

        private void SetTypeCValue()
        {

            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            int FTWidth = theFooting.Width;
            int FTLen = theFooting.Length;
            int db = (int)MainRebarDB;
            int NumMainAll = MainWBarDistributeC.Location.Count * 2 + MainLBarDistributeC.Location.Count * 2 + 4;
            int NumMainAllA = MainWBarDistribute.Location.Count * 2 + MainLBarDistribute.Location.Count * 2 + 4;
            int NumMainAllB = MainWBarDistributeB.Location.Count * 2 + MainLBarDistributeB.Location.Count * 2 + 4;
            #region 3-锚固筋
            int A = 0;
            //int Z1 = 8483 - (FTHeight - 185) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200
            //if (SubType == eSubType.C || SubType == eSubType.D)
            //    Z1 = 11483 - (FTHeight - 185) - 1200;
            #region 9/12m 250搭接
            int Z1 = 8494 - (FTHeight - 185) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200

            if (SubType == eSubType.C || SubType == eSubType.D)
                Z1 = 11494 - (FTHeight - 185) - 1200;
            #endregion
            int L2 = 0;// 盖梁锚固筋长度；
            int L12Num = 0;
            bool isDiv = false;

            int aa = (int)(1300 + LenUpper);
            if (PierHeight - Z1 + 1200 + 1500 > 12000)
            {
                // 分3节
                L12Num = NumMainAll;
                isDiv = true;
                //L2 = (PierHeight - Z1 + 1200 + 1500 - aa);
                L2 = (PierHeight - Z1 + 1200 - aa);
                if (L2 + 1200 * 2 > 12000 - 250 + 248)
                {
                    aa += L2 + 1200 * 2 - (12000 - 250 + 248);
                    L2 = 12000 - 250 + 248 - 2400;
                }
            }
            else
            {
                int numA = MainWBarDistribute.Location.Count;
                // 分2节
                L2 = 1500 + (PierHeight - Z1) + 1200; // 深入盖梁钢筋总长度    
                aa = L2 - 1500;
            }

            CrossbeamBase theCB = MemberFactory.CreatMember(MemberFactory.ColumnToCrossBeam(ColumnType), 0);
            NumMainAll = MainLBarDistributeB.Location.Count * 2 + MainWBarDistributeB.Location.Count * 2 + 4;
            int NumL = 0;//外侧L数量

            int NumS = 0;//直线
            int bb = 0;
            int cc = 0;//1500-(B-r/2-d);
            int dd = 0;
        
            int rr = RebarKnowledge.GerRadius(eDB.DB32);
            string no = "a";
            // 5.2a为L锚固
            // 是否与预应力冲突 ？Y:B=100
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb - rr * 0.5 - 32);
                NumL += MainWBarDistributeB.Location.Count * 2 + 4;
              
            }
            else
            {
                // 此时，W主筋无需避让预应力，应分析是否可以直锚？
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否在安全距离
                foreach (double item in MainLBarDistributeB.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;

                }
                if (isEixt)//与盖梁顶部安全距离判断；
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumL += MainWBarDistributeB.Location.Count * 2 + 4;
                    //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                    //no = "b";
                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumS += MainWBarDistributeB.Location.Count * 2 + 4;
                    //RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb));                  
                    //no = "b";
                }
            }
            int numL = 0, numS = 0; //避开预应力的主筋直线和L数量
            int numLC = 0, numSC = 0;
            int NumLC = 0;//不冲突的
            int i = 0;
            Dictionary<int, string> dicDY = new Dictionary<int, string>();
            
            if (MainLBarDistributeC.Location.Count > MainLBarDistributeB.Location.Count && MainLBarDistributeC.Location.Count== MainLBarDistribute.Location.Count)
            {
                foreach (double item in MainLBarDistributeB.Location.Values)
                {
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                    {
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        numL++;
                        dicDY.Add(i, "L");
                    }
                    else //安全距离之内 
                    {
                        bool isSpecial = false;
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (itemY == 0 && item == 0)
                            {
                                isSpecial = true;
                                break;
                            }
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        if (!isSpecial)
                        {
                            if (!isConflict)
                            {
                                numS++;
                                dicDY.Add(i, "直线");
                            }
                            else
                            {
                                dicDY.Add(i, "闪电");
                            }
                        }
                        else
                        {
                            numL++;
                            dicDY.Add(i, "L");
                        }
                    }
                    i++;
                }

                string mesage = "";
                foreach (int key in dicDY.Keys)
                {

                    TextOper.WriteFile(key, dicDY[key], "PTM1" + SubType.ToString());
                }

                i = 0;
                Dictionary<int, string> dicCDY = new Dictionary<int, string>();
                foreach (double item in MainLBarDistributeC.Location.Values)
                {
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                    {
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        //if (!isConflict)
                        //    NumLC++;
                        //else
                        numLC++;
                        dicCDY.Add(i, "L");
                    }
                    else //安全距离之内 
                    {
                        bool isSpecial = false;
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (itemY == 0 && item == 0)
                            {
                                isSpecial = true;
                                break;
                            }
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        if (!isSpecial)
                        {
                            if (!isConflict)
                            {
                                numSC++;
                                dicCDY.Add(i, "直线");
                            }
                            else
                            {
                                dicCDY.Add(i, "闪电");
                            }
                        }
                        else
                        {
                            numLC++;
                            dicCDY.Add(i, "L");
                        }
                    }
                    i++;
                }

                foreach (int key in dicCDY.Keys)
                {

                    TextOper.WriteFile(key, dicCDY[key], "PTM1" + SubType.ToString() + "A截面");
                }
            }
            else
            {

            }



            NumS += 1 * 2;

         
            NumL += numL * 2 + NumLC * 2-2;
            NumLC = NumLC * 2;

          
            //其他
            int NumLS = NumMainAll - NumS - NumL;//闪电型    
            NumL = 12;
            NumLS = 16;
            if (NumS > 0)
            {
                A = aa;
                //直线锚固
                //RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumS, eShapeType.MLS, aa, 1500));
                //if (no == "a")
                //    no = "b";
                //else if (no == "b")
                //    no = "c";
                //else if (no == "c")
                //    no = "d";
                //else if (no == "d")
                //    no = "e";
                //else if (no == "e")
                //    no = "f";
                //else if (no == "f")
                //    no = "g";
                //else
                //    no = "h";
            }
            if (NumLS > 0)
            {
                bb = 100;
                cc = 180;
                dd = 1500 - 100 - 180;
                int numAll = 0;
                foreach (var key in dic.Keys)
                {
                    numAll += dic[key].Count * 2;
                }
                if (numAll > 0)
                {
                    foreach (var key in dic.Keys)
                    {
                        cc = (int)key;
                        dd = 1500 - 100 - (int)key;
                        int count = dic[key].Count * 2;
                        //闪电锚固
                        RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else if (no == "e")
                            no = "f";
                        else if (no == "f")
                            no = "g";
                        else
                            no = "h";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, NumLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }

            }
            if (NumL > 0)
            {
                //NumL=
                //L锚固
                if (NumLC > 0)
                {
                    bb = 100;
                 
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumL - NumLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, 12, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumL - NumLC > 0)
                {
                    bb = theCB.CalculatedHeight - 200;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, 16, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
            }
            if (isDiv)
            {
                RebarList.Add(new MSZRebarRecord(5, 3, "", MainRebarDB, NumMainAllB, eShapeType.MSZ, L2 + 1200 * 2));
            }
            #endregion

            #region 4 起步加强筋6.1
            int add = 1;
            int NumAddOFout = 0;// 外向起步筋
            int NumAddMainAll = AddWBarDistributeC.Location.Count * 2 + AddLBarDistributeC.Location.Count * 2;
            if (NumAddMainAll > 0)
            {
                if ((FTWidth - Width) * 0.5 >= 600)
                {
                    NumAddOFout += AddLBarDistributeC.Location.Count * 2;
                }
                if ((FTLen - Length) * 0.5 >= 600)
                {
                    NumAddOFout += AddWBarDistributeC.Location.Count * 2;
                }
                if (SubType == eSubType.C)
                    NumAddMainAll = 10;
                string no6 = "a";
                if (NumAddMainAll - NumAddOFout > 0)
                {

                    if (SubType == eSubType.C)
                    {
                        int len = 5365;
                        RebarList.Add(new MHXARebarRecord(6, 1, no6, MainRebarDB, true, NumAddMainAll - NumAddOFout, eShapeType.MHXA, len));
                    }
                    else
                        RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, true, NumAddMainAll - NumAddOFout, eShapeType.MHX));
                    no6 = "b";
                }
                //5.1b为外侧起步筋；
                if (NumAddOFout != 0)
                {
                    if (no6 == "a")
                        no6 = "";
                    if (SubType == eSubType.C)
                    {
                        RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, false, NumAddOFout, eShapeType.MHXe));
                    }
                    else
                        RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, false, NumAddOFout, eShapeType.MHXe));
                }
                add = 2;
            }
            #endregion

        

            #region 5 加强锚固6.1
            int NumAddL = 0;//外侧L数量
            int NumAddS = 0; //直线数量
            int NumAddAll = AddWBarDistribute.Location.Count * 2 + AddLBarDistribute.Location.Count * 2;
            aa = (int)(1300 + LenUpper);
            no = "a";
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb + rr * 0.5 + 32);
                NumAddL += AddWBarDistribute.Location.Count * 2;
                //if (NumAddL > 0)
                //{
                //    RebarList.Add(new MLRebarRecord(5, 3, no, MainRebarDB, NumAddL, eShapeType.ML, aa, bb, cc, rr));
                //    no = "b";
                //}
            }
            else
            {
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否安全距离内
                foreach (double item in AddLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;
                }
                if (isEixt)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
            }

            int numAddL = 0, numAddS = 0;//避开预应力的加强筋直线和L数量
            int NumAddLC = 0;//冲突
            int n = 0;
            Dictionary<int, string> dicAddDY = new Dictionary<int, string>();

            foreach (double item in AddLBarDistribute.Location.Values)
            {
                if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                {

                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {

                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (!isConflict)
                    //    NumAddLC++;
                    //else
                    numAddL++;
                    dicAddDY.Add(n, "L");
                }
                else //安全距离之内 直线
                {
                    bool isConflict = false;
                    bool isSpecial = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (itemY == 0 && item == 0)
                        {
                            isSpecial = true;
                            break;
                        }
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (isConflict)
                    //    numAddS++;
                    if (!isSpecial)
                    {
                        if (!isConflict)
                        {
                            numAddS++;
                            dicAddDY.Add(n, "直线");
                        }
                        else
                        {
                            dicAddDY.Add(n, "闪电");
                        }
                    }
                    else
                    {
                        numAddL++;
                        dicAddDY.Add(n, "L");
                    }

                }
                n++;
            }
            //numAddLL = numAddLL * 2;
            NumAddS += numAddS * 2;
            NumAddL += numAddL * 2 + NumAddLC * 2;
            NumAddLC = NumAddLC * 2;
            //其他的闪电锚固
            int NumAddLS = NumAddAll - NumAddS - NumAddL + (NumMainAllA - NumMainAll - (numSC - numS) * 2 - (numLC - numL) * 2);
            NumAddS += (numSC - numS) * 2;
            NumAddL += (numLC - numL) * 2;
            NumAddS = 4;
            NumAddLS = 8;
            NumAddL = 16;
            RebarList.Add(new MLSRebarRecord(6, 2, no, MainRebarDB, NumS, eShapeType.MLS, aa, 1500));
            no = "b";
            cc = (int)125;
            dd = 1500 - 100 - (int)125;
         
            //闪电锚固
            RebarList.Add(new MLZRebarRecord(6, 2, no, MainRebarDB, 4, eShapeType.MLZ, aa, 100, cc, dd));
            no = "c";
            //if (NumAddS > 0)
            //{
            //    RebarList.Add(new MLSRebarRecord(6, add, no, MainRebarDB, NumAddS, eShapeType.MLS, aa, 1500));
            //    if (no == "a")
            //        no = "b";
            //    else if (no == "b")
            //        no = "c";
            //    else if (no == "c")
            //        no = "d";
            //    else if (no == "d")
            //        no = "e";
            //    else if (no == "e")
            //        no = "f";
            //    else if (no == "f")
            //        no = "g";
            //    else
            //        no = "h";
            //}

            if (NumAddLS > 0)
            {
                cc = 180;
                bb = 100;
                dd = 1500 - 180 - 100;
                int numAll = 0;
                foreach (var key in addDic.Keys)
                {
                    numAll += addDic[key].Count * 2;
                }
                if (numAll > 0)
                {
                    int all = 0;
                    int m = 0;
                    foreach (var key in addDic.Keys)
                    {
                        cc = (int)key;
                        dd = 1500 - 100 - (int)key;
                        int count = addDic[key].Count * 2;
                        if (addDic.Count == 1)
                            RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, NumAddLS, eShapeType.MLZ, aa, bb, cc, dd));
                        else
                        {
                            all += addDic[key].Count * 2;
                            if (m == 1)
                                count = NumAddLS - (all - addDic[key].Count * 2);
                            //闪电锚固
                            RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                            m++;
                        }
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else if (no == "e")
                            no = "f";
                        else if (no == "f")
                            no = "g";
                        else
                            no = "h";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, NumAddLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
            }
            if (NumAddL > 0)
            {

                if (NumAddL - NumAddLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(6, add, no, MainRebarDB, NumAddL - NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumAddLC > 0)
                {

                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);

                    RebarList.Add(new MLRebarRecord(6, add, no, MainRebarDB, NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                }
            }
            #endregion

            #region UBlot数量计算
            if (isDiv)
                UAN1N2 = NumMainAll * 8;
            else
                UAN1N2 = NumMainAll * 4;
            if (isDiv)
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 8;
            }
            else
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 4;
            }
            #endregion
        }

        private void  SetTypeDValue()
        {
            #region
            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            int FTWidth = theFooting.Width;
            int FTLen = theFooting.Length;
            int db = (int)MainRebarDB;
            int NumMainAll = MainWBarDistribute.Location.Count * 2 + MainLBarDistribute.Location.Count * 2 + 4;
            #endregion

            #region 3-锚固筋
            //int Z1 = 8483 - (FTHeight - 185) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200
            //if (SubType == eSubType.C || SubType == eSubType.D)                                        //12米
            //    Z1 = 11483 - (FTHeight - 185) - 1200;
            #region 9/12m 250搭接
            int Z1 = 8494 - (FTHeight - 185) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200

            if (SubType == eSubType.C || SubType == eSubType.D)
                Z1 = 11494 - (FTHeight - 185) - 1200;
            #endregion
            int L2 = 0;// 盖梁锚固筋长度；
            int L12Num = 0;
            bool isDiv = false;

            int aa = (int)(1300 + LenUpper);
            if (PierHeight - Z1 + 1200 + 1500 > 12000)
            {
                // 分3节
                L12Num = NumMainAll;
                isDiv = true;
                //L2 = (PierHeight - Z1 + 1200 + 1500 - aa);
                L2 = (PierHeight - Z1 + 1200 - aa);
                if (L2 + 1200 * 2 > 12000 - 250 + 248)
                {
                    aa += L2 + 1200 * 2 - (12000 - 250 + 248);
                    L2 = 12000 - 250 + 248 - 2400;
                }
            }
            else
            {
                int numA = MainWBarDistribute.Location.Count;
                // 分2节
                L2 = 1500 + (PierHeight - Z1) + 1200; // 深入盖梁钢筋总长度    
                aa = L2 - 1500;
            }

            CrossbeamBase theCB = MemberFactory.CreatMember(MemberFactory.ColumnToCrossBeam(ColumnType), 0);
            NumMainAll = MainLBarDistribute.Location.Count * 2 + MainWBarDistribute.Location.Count * 2 + 4;
            int NumL = 0;//外侧L数量

            int NumS = 0;//直线
            int bb = 0;
            int cc = 0;//1500-(B-r/2-d);
            int dd = 0;
            //int aa = L2 - 1500;         
            //if (L2 - 1500 < 0)
            //    aa = 0;
            int rr = RebarKnowledge.GerRadius(eDB.DB32);
            string no = "a";
            // 5.2a为L锚固
            // 是否与预应力冲突 ？Y:B=100
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb - rr * 0.5 - 32);
                NumL += MainWBarDistribute.Location.Count * 2 + 4;
                //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                //no = "b";
            }
            else
            {
                // 此时，W主筋无需避让预应力，应分析是否可以直锚？
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否在安全距离
                foreach (double item in MainLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;

                }
                if (isEixt)//与盖梁顶部安全距离判断；
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumL += MainWBarDistribute.Location.Count * 2 + 4;
                    //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                    //no = "b";
                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumS += MainWBarDistribute.Location.Count * 2 + 4;
                    //RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb));                  
                    //no = "b";
                }
            }
            int NumLSZ = 0;
            ////预应力冲突 闪电避让
            //foreach (double item in MainLBarDistribute.Location.Values)
            //{
            //    foreach (double itemY in theCB.TendonDistribute.Location.Values)
            //    {
            //        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
            //            NumLSZ++;
            //    }
            //}
            int numL = 0, numS = 0; //避开预应力的主筋直线和L数量
            int NumLC = 0;//不冲突的
            int i = 0;
            Dictionary<int, string> dicDY = new Dictionary<int, string>();
            foreach (double item in MainLBarDistribute.Location.Values)
            {
                if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                {
                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    if (isConflict)
                        NumLC++;
                    else
                        numL++;
                    dicDY.Add(i, "L");
                }
                else //安全距离之内 
                {
                    bool isSpecial = false;
                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (itemY == 0 && item == 0)
                        {
                            isSpecial = true;
                            break;
                        }
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    if (!isSpecial)
                    {
                        if (!isConflict)
                        {
                            numS++;
                            dicDY.Add(i, "直线");
                        }
                        else
                        {
                            dicDY.Add(i, "闪电");
                        }
                    }
                    else
                    {
                        numL++;
                        dicDY.Add(i, "L");
                    }
                }
                i++;
            }

            string mesage = "";
            foreach (int key in dicDY.Keys)
            {

                TextOper.WriteFile(key, dicDY[key], "PTM1S");
            }


            NumS += numS * 2;
            NumL += numL * 2 + NumLC * 2;
            NumLC = NumLC * 2;
            NumLC = NumL - 12;
            //其他
            int NumLS = NumMainAll - NumS - NumL;//闪电型         
            if (NumS > 0)
            {
                //直线锚固
                RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumS, eShapeType.MLS, aa, 1500));
                if (no == "a")
                    no = "b";
                else if (no == "b")
                    no = "c";
                else if (no == "c")
                    no = "d";
                else if (no == "d")
                    no = "e";
                else if (no == "e")
                    no = "f";
                else if (no == "f")
                    no = "g";
                else
                    no = "h";
            }
            if (NumLS > 0)
            {
                bb = 100;
                cc = 180;
                dd = 1500 - 100 - 180;
                int numAll = 0;
                foreach (var key in dic.Keys)
                {
                    numAll += dic[key].Count * 2;
                }
                if (numAll == NumLS)
                {
                    foreach (var key in dic.Keys)
                    {
                        cc = (int)key;
                        dd = 1500 - 100 - (int)key;
                        int count = dic[key].Count * 2;
                        //闪电锚固
                        RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else if (no == "e")
                            no = "f";
                        else if (no == "f")
                            no = "g";
                        else
                            no = "h";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, NumLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }

            }
            if (NumL > 0)
            {
                //L锚固

                if (NumL - NumLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL - NumLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumLC > 0)
                {
                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
            }
            if (isDiv)
            {
                RebarList.Add(new MSZRebarRecord(5, 3, "", MainRebarDB, NumMainAll, eShapeType.MSZ, L2 + 1200 * 2));
            }
            #endregion


            #region 4 起步加强筋6.1
            int add = 1;
            int NumAddOFout = 0;// 外向起步筋
            int NumAddMainAll = AddWBarDistributeC.Location.Count * 2 + AddLBarDistributeC.Location.Count * 2;
            if (NumAddMainAll > 0)
            {
                if ((FTWidth - Width) * 0.5 >= 600)
                {
                    NumAddOFout += AddLBarDistributeC.Location.Count * 2;
                }
                if ((FTLen - Length) * 0.5 >= 600)
                {
                    NumAddOFout += AddWBarDistributeC.Location.Count * 2;
                }

                string no6 = "a";
                if (NumAddMainAll - NumAddOFout > 0)
                {
                    RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, true, NumAddMainAll - NumAddOFout, eShapeType.MHX));
                    no6 = "b";
                }
                //5.1b为外侧起步筋；
                if (NumAddOFout != 0)
                {
                    if (no6 == "a")
                        no6 = "";
                    RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, false, NumAddOFout, eShapeType.MHXe));
                }
                add = 2;
            }
            #endregion

            #region 5 加强锚固6.2
            int NumAddL = 0;//外侧L数量
            int NumAddS = 0; //直线数量
            int NumAddAll = AddWBarDistribute.Location.Count * 2 + AddLBarDistribute.Location.Count * 2;
            aa = (int)(1300 + LenUpper);
            no = "a";
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb + rr * 0.5 + 32);
                NumAddL += AddWBarDistribute.Location.Count * 2;
                //if (NumAddL > 0)
                //{
                //    RebarList.Add(new MLRebarRecord(5, 3, no, MainRebarDB, NumAddL, eShapeType.ML, aa, bb, cc, rr));
                //    no = "b";
                //}
            }
            else
            {
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否安全距离内
                foreach (double item in AddLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;
                }
                if (isEixt)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
            }

            int numAddL = 0, numAddS = 0;//避开预应力的加强筋直线和L数量
            int NumAddLC = 0;//冲突
            int n = 0;
            Dictionary<int, string> dicAddDY = new Dictionary<int, string>();

            foreach (double item in AddLBarDistribute.Location.Values)
            {
                if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                {

                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {

                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    if (isConflict)
                        NumAddLC++;
                    else
                        numAddL++;
                    dicAddDY.Add(n, "L");
                }
                else //安全距离之内 直线
                {
                    bool isConflict = false;
                    bool isSpecial = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (itemY == 0 && item == 0)
                        {
                            isSpecial = true;
                            break;
                        }
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (isConflict)
                    //    numAddS++;
                    if (!isSpecial)
                    {
                        if (!isConflict)
                        {
                            numAddS++;
                            dicAddDY.Add(n, "直线");
                        }
                        else
                        {
                            dicAddDY.Add(n, "闪电");
                        }
                    }
                    else
                    {
                        numAddL++;
                        dicAddDY.Add(n, "L");
                    }

                }
                n++;
            }
            //numAddLL = numAddLL * 2;
            NumAddS += numAddS * 2;
            NumAddL += numAddL * 2 + NumAddLC * 2;
            NumAddLC = NumAddLC * 2;
            //其他的闪电锚固
            int NumAddLS = NumAddAll - NumAddS - NumAddL;

            if (NumAddS > 0)
            {
                RebarList.Add(new MLSRebarRecord(6, add, no, MainRebarDB, NumAddS, eShapeType.MLS, aa, 1500));
                if (no == "a")
                    no = "b";
                else if (no == "b")
                    no = "c";
                else if (no == "c")
                    no = "d";
                else if (no == "d")
                    no = "e";
                else if (no == "e")
                    no = "f";
                else if (no == "f")
                    no = "g";
                else
                    no = "h";
            }

            if (NumAddLS > 0)
            {
                cc = 180;
                bb = 100;
                dd = 1500 - 180 - 100;
                int numAll = 0;
                foreach (var key in addDic.Keys)
                {
                    numAll += addDic[key].Count * 2;
                }
                if (numAll == NumAddLS)
                {
                    foreach (var key in addDic.Keys)
                    {
                        cc = (int)key;
                        dd = 1500 - 100 - (int)key;
                        int count = addDic[key].Count * 2;
                        //闪电锚固
                        RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else if (no == "e")
                            no = "f";
                        else if (no == "f")
                            no = "g";
                        else
                            no = "h";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, NumAddLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
            }
            if (NumAddL > 0)
            {

                if (NumAddL - NumAddLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(6, add, no, MainRebarDB, NumAddL - NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumAddLC > 0)
                {

                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);

                    RebarList.Add(new MLRebarRecord(6, add, no, MainRebarDB, NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                }
            }
            #endregion

            #region UBlot数量计算
            if (isDiv)
                UAN1N2 = NumMainAll * 8;
            else
                UAN1N2 = NumMainAll * 4;
            if (isDiv)
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 8;
            }
            else
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 4;
            }
            #endregion
        }

        private void SetTypeBValue()
        {
        
            FootingBase theFooting = MemberFactory.CreatMember(MemberFactory.FromColumnToFooting(ColumnType), SubType);
            int FTHeight = theFooting.Height;
            int FTWidth = theFooting.Width;
            int FTLen = theFooting.Length;
            int db = (int)MainRebarDB;
            int NumMainAll = MainWBarDistributeC.Location.Count * 2 + MainLBarDistributeC.Location.Count * 2 + 4;
            int NumMainAllA = MainWBarDistribute.Location.Count * 2 + MainLBarDistribute.Location.Count * 2 + 4;
            #region 3-锚固筋

            //int Z1 = 8483 - (FTHeight - 185) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200
            #region 9/12m 250搭接
            int Z1 = 8494 - (FTHeight - 185) - 1200; // 搭接节点 1//Z1=8483-(H-160)-1200

            if (SubType == eSubType.C || SubType == eSubType.D)
                Z1 = 11494 - (FTHeight - 185) - 1200;
            #endregion
            int L2 = 0;// 盖梁锚固筋长度；
            int L12Num = 0;
            bool isDiv = false;

            int aa = (int)(1300 + LenUpper);
            if (PierHeight - Z1 + 1200 + 1500 > 12000)
            {
                // 分3节
                L12Num = NumMainAll;
                isDiv = true;
                //L2 = (PierHeight - Z1 + 1200 + 1500 - aa);
                L2 = (PierHeight - Z1 + 1200 - aa);
                if (L2 + 1200 * 2 > 12000 - 250 + 248)
                {
                    aa += L2 + 1200 * 2 - (12000 - 250 + 248);
                    L2 = 12000 - 250 + 248 - 2400;
                }
            }
            else
            {
                int numA = MainWBarDistribute.Location.Count;
                // 分2节
                L2 = 1500 + (PierHeight - Z1) + 1200; // 深入盖梁钢筋总长度    
                aa = L2 - 1500;
            }

            CrossbeamBase theCB = MemberFactory.CreatMember(MemberFactory.ColumnToCrossBeam(ColumnType), 0);
            NumMainAll = MainLBarDistributeC.Location.Count * 2 + MainWBarDistributeC.Location.Count * 2 + 4;
            int NumL = 0;//外侧L数量

            int NumS = 0;//直线
            int bb = 0;
            int cc = 0;//1500-(B-r/2-d);
            int dd = 0;
            //int aa = L2 - 1500;         
            //if (L2 - 1500 < 0)
            //    aa = 0;
            int rr = RebarKnowledge.GerRadius(eDB.DB32);
            string no = "a";
            // 5.2a为L锚固
            // 是否与预应力冲突 ？Y:B=100
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb - rr * 0.5 - 32);
                NumL += MainWBarDistributeC.Location.Count * 2 + 4;
                //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                //no = "b";
            }
            else
            {
                // 此时，W主筋无需避让预应力，应分析是否可以直锚？
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否在安全距离
                foreach (double item in MainLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;

                }
                if (isEixt)//与盖梁顶部安全距离判断；
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumL += MainWBarDistributeC.Location.Count * 2 + 4;
                    //RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb, cc, rr));
                    //no = "b";
                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumS += MainWBarDistributeC.Location.Count * 2 + 4;
                    //RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumL, eShapeType.ML, aa, bb));                  
                    //no = "b";
                }
            }
            int NumLSZ = 0;
            ////预应力冲突 闪电避让
            //foreach (double item in MainLBarDistribute.Location.Values)
            //{
            //    foreach (double itemY in theCB.TendonDistribute.Location.Values)
            //    {
            //        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
            //            NumLSZ++;
            //    }
            //}
            int numL = 0, numS = 0; //避开预应力的主筋直线和L数量
            int numLC = 0, numSC = 0;
            int NumLC = 0;//不冲突的
            int i = 0;
            Dictionary<int, string> dicDY = new Dictionary<int, string>();
            if (MainLBarDistribute.Location.Count == MainLBarDistributeC.Location.Count)
            {

                foreach (double item in MainLBarDistribute.Location.Values)
                {
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                    {
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        //if (!isConflict)
                        //    NumLC++;
                        //else
                        numL++;
                        dicDY.Add(i, "L");
                    }
                    else //安全距离之内 
                    {
                        bool isSpecial = false;
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (itemY == 0 && item == 0)
                            {
                                isSpecial = true;
                                break;
                            }
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        if (!isSpecial)
                        {
                            if (!isConflict)
                            {
                                numS++;
                                dicDY.Add(i, "直线");
                            }
                            else
                            {
                                dicDY.Add(i, "闪电");
                            }
                        }
                        else
                        {
                            numL++;
                            dicDY.Add(i, "L");
                        }
                    }
                    i++;
                }

                string mesage = "";
                foreach (int key in dicDY.Keys)
                {

                    TextOper.WriteFile(key, dicDY[key], "PTM1S-" + SubType.ToString());
                }

            }
            else if (MainLBarDistribute.Location.Count > MainLBarDistributeC.Location.Count)
            {
                foreach (double item in MainLBarDistributeC.Location.Values)
                {
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                    {
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        //if (!isConflict)
                        //    NumLC++;
                        //else
                            numL++;
                        dicDY.Add(i, "L");
                    }
                    else //安全距离之内 
                    {
                        bool isSpecial = false;
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (itemY == 0 && item == 0)
                            {
                                isSpecial = true;
                                break;
                            }
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        if (!isSpecial)
                        {
                            if (!isConflict)
                            {
                                numS++;
                                dicDY.Add(i, "直线");
                            }
                            else
                            {
                                dicDY.Add(i, "闪电");
                            }
                        }
                        else
                        {
                            numL++;
                            dicDY.Add(i, "L");
                        }
                    }
                    i++;
                }

                string mesage = "";
                foreach (int key in dicDY.Keys)
                {

                    TextOper.WriteFile(key, dicDY[key], "PTM1S-" + SubType.ToString());
                }

                i = 0;
                Dictionary<int, string> dicCDY = new Dictionary<int, string>();
                foreach (double item in MainLBarDistribute.Location.Values)
                {
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                    {
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        //if (!isConflict)
                        //    NumLC++;
                        //else
                            numLC++;
                        dicCDY.Add(i, "L");
                    }
                    else //安全距离之内 
                    {
                        bool isSpecial = false;
                        bool isConflict = false;
                        foreach (double itemY in theCB.TendonDistribute.Location.Values)
                        {
                            if (itemY == 0 && item == 0)
                            {
                                isSpecial = true;
                                break;
                            }
                            if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                            {
                                isConflict = true;
                                break;
                            }
                        }
                        if (!isSpecial)
                        {
                            if (!isConflict)
                            {
                                numSC++;
                                dicCDY.Add(i, "直线");
                            }
                            else
                            {
                                dicCDY.Add(i, "闪电");
                            }
                        }
                        else
                        {
                            numLC++;
                            dicCDY.Add(i, "L");
                        }
                    }
                    i++;
                }

                foreach (int key in dicCDY.Keys)
                {

                    TextOper.WriteFile(key, dicCDY[key], "PTM1S-" + SubType.ToString() + "A截面");
                }
            }
            else
            {

            }



            NumS += numS * 2;

          
            NumL += numL * 2 + NumLC * 2;
            NumLC = NumL-12;
           

            //其他
            int NumLS = NumMainAll - NumS - NumL;//闪电型         
            if (NumS > 0)
            {
                //直线锚固
                RebarList.Add(new MLSRebarRecord(5, 2, no, MainRebarDB, NumS, eShapeType.MLS, aa, 1500));
                if (no == "a")
                    no = "b";
                else if (no == "b")
                    no = "c";
                else if (no == "c")
                    no = "d";
                else if (no == "d")
                    no = "e";
                else if (no == "e")
                    no = "f";
                else if (no == "f")
                    no = "g";
                else
                    no = "h";
            }
            if (NumLS > 0)
            {
                bb = 100;
                cc = 180;
                dd = 1500 - 100 - 180;
                int numAll = 0;
                foreach (var key in dic.Keys)
                {
                    numAll += dic[key].Count * 2;
                }
                if (numAll > 0)
                {
                    foreach (var key in dic.Keys)
                    {
                        cc = (int)key;
                        dd = 1500 - 100 - (int)key;
                        int count = dic[key].Count * 2;
                        //闪电锚固
                        RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else if (no == "e")
                            no = "f";
                        else if (no == "f")
                            no = "g";
                        else
                            no = "h";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(5, 2, no, MainRebarDB, NumLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }

            }
            if (NumL > 0)
            {
                //L锚固
              
                if (NumL - NumLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumL - NumLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumLC > 0)
                {
                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(5, 2, no, MainRebarDB, NumLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
            }
            if (isDiv)
            {
                RebarList.Add(new MSZRebarRecord(5, 3, "", MainRebarDB, NumMainAll, eShapeType.MSZ, L2 + 1200 * 2));
            }
            #endregion

            #region 4 起步加强筋6.1
            int add = 1;
            int NumAddOFout = 0;// 外向起步筋
            int NumAddMainAll = AddWBarDistributeC.Location.Count * 2 + AddLBarDistributeC.Location.Count * 2;
            if (NumAddMainAll > 0)
            {
                if ((FTWidth - Width) * 0.5 >= 600)
                {
                    NumAddOFout += AddLBarDistributeC.Location.Count * 2;
                }
                if ((FTLen - Length) * 0.5 >= 600)
                {
                    NumAddOFout += AddWBarDistributeC.Location.Count * 2;
                }

                string no6 = "a";
                if (NumAddMainAll - NumAddOFout > 0)
                {
                    RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, true, NumAddMainAll - NumAddOFout, eShapeType.MHX));
                    no6 = "b";
                }
                //5.1b为外侧起步筋；
                if (NumAddOFout != 0)
                {
                    if (no6 == "a")
                        no6 = "";
                    RebarList.Add(new MHXRebarRecord(6, 1, no6, MainRebarDB, false, NumAddOFout, eShapeType.MHXe));
                }
                add = 2;
            }
            #endregion

            #region 5 加强锚固6.1/6.2
            int NumAddL = 0;//外侧L数量
            int NumAddS = 0; //直线数量
            int NumAddAll = AddWBarDistribute.Location.Count * 2 + AddLBarDistribute.Location.Count * 2;
            aa = (int)(1300 + LenUpper);
            no = "a";
            if (Math.Abs(Length - 50 - 12 - 16 - theCB.TendonDistribute.Location[0] * -1) <= theCB.TendonDistribute.Diameter * 0.5)
            {
                // 外侧主筋L型避让
                bb = 100;
                cc = (int)(1500 - bb + rr * 0.5 + 32);
                NumAddL += AddWBarDistribute.Location.Count * 2;
                //if (NumAddL > 0)
                //{
                //    RebarList.Add(new MLRebarRecord(5, 3, no, MainRebarDB, NumAddL, eShapeType.ML, aa, bb, cc, rr));
                //    no = "b";
                //}
            }
            else
            {
                // 若无预应力冲突，但盖梁空间不足，B=theCB.CalculatedHeight-100
                // 外侧主筋L型避让
                bool isEixt = false;//是否安全距离内
                foreach (double item in AddLBarDistribute.Location.Values)
                {
                    //第一个对比
                    if (Math.Abs(item) > theCB.L2 * 0.5 - 82)
                    {
                        isEixt = true;
                    }
                    break;
                }
                if (isEixt)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
                else
                {
                    //直线布置 长度A+B
                    bb = 1500;
                    NumAddL += AddWBarDistribute.Location.Count * 2;

                }
            }

            int numAddL = 0, numAddS = 0;//避开预应力的加强筋直线和L数量
            int NumAddLC = 0;//冲突
            int n = 0;
            Dictionary<int, string> dicAddDY = new Dictionary<int, string>();

            foreach (double item in AddLBarDistribute.Location.Values)
            {
                if (Math.Abs(item) > theCB.L2 * 0.5 - 82)//安全距离之外 L
                {

                    bool isConflict = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {

                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }
                    //if (!isConflict)
                    //    NumAddLC++;
                    //else
                        numAddL++;
                    dicAddDY.Add(n, "L");
                }
                else //安全距离之内 直线
                {
                    bool isConflict = false;
                    bool isSpecial = false;
                    foreach (double itemY in theCB.TendonDistribute.Location.Values)
                    {
                        if (itemY == 0 && item == 0)
                        {
                            isSpecial = true;
                            break;
                        }
                        if (Math.Abs(itemY - item) < theCB.TendonDistribute.Diameter * 0.5)
                        {
                            isConflict = true;
                            break;
                        }
                    }                   
                    if (!isSpecial)
                    {
                        if (!isConflict)
                        {
                            numAddS++;
                            dicAddDY.Add(n, "直线");
                        }
                        else
                        {
                            dicAddDY.Add(n, "闪电");
                        }
                    }
                    else
                    {
                        numAddL++;
                        dicAddDY.Add(n, "L");
                    }

                }
                n++;
            }
            //numAddLL = numAddLL * 2;
            NumAddS += numAddS * 2;
            NumAddL += numAddL * 2 + NumAddLC * 2;
            NumAddLC = NumAddLC * 2;
            //其他的闪电锚固
            int NumAddLS = NumAddAll - NumAddS - NumAddL + (NumMainAllA - NumMainAll - (numSC - numS) * 2 - (numLC - numL) * 2);
            NumAddS += (numSC - numS) * 2;
            NumAddL += (numLC - numL) * 2;
            if (NumAddS > 0)
            {
                RebarList.Add(new MLSRebarRecord(6, add, no, MainRebarDB, NumAddS, eShapeType.MLS, aa, 1500));
                if (no == "a")
                    no = "b";
                else if (no == "b")
                    no = "c";
                else if (no == "c")
                    no = "d";
                else if (no == "d")
                    no = "e";
                else if (no == "e")
                    no = "f";
                else if (no == "f")
                    no = "g";
                else
                    no = "h";
            }

            if (NumAddLS > 0)
            {
                cc = 180;
                bb = 100;
                dd = 1500 - 180 - 100;
                int numAll = 0;
                foreach (var key in addDic.Keys)
                {
                    numAll += addDic[key].Count * 2;
                }
                if (numAll > 0)
                {
                    int all = 0;
                    int m = 0;
                    foreach (var key in addDic.Keys)
                    {
                        cc = (int)key;
                        dd = 1500 - 100 - (int)key;
                        int count = addDic[key].Count * 2;
                        if (addDic.Count == 1)
                            RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, NumAddLS, eShapeType.MLZ, aa, bb, cc, dd));
                        else
                        {
                            all += addDic[key].Count * 2;
                            if (m == 1)
                                count = NumAddLS - (all - addDic[key].Count * 2);
                            //闪电锚固
                            RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, count, eShapeType.MLZ, aa, bb, cc, dd));
                            m++;
                        }
                        if (no == "a")
                            no = "b";
                        else if (no == "b")
                            no = "c";
                        else if (no == "c")
                            no = "d";
                        else if (no == "d")
                            no = "e";
                        else if (no == "e")
                            no = "f";
                        else if (no == "f")
                            no = "g";
                        else
                            no = "h";
                    }
                }
                else
                {
                    RebarList.Add(new MLZRebarRecord(6, add, no, MainRebarDB, NumAddLS, eShapeType.MLZ, aa, bb, cc, dd));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
            }
            if (NumAddL > 0)
            {
                if (NumAddLC > 0)
                {

                    bb = 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);

                    RebarList.Add(new MLRebarRecord(6, add, no, MainRebarDB, NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
                if (NumAddL - NumAddLC > 0)
                {
                    bb = theCB.CalculatedHeight - 100;
                    cc = (int)(1500 - bb + rr * 0.5 + 32);
                    RebarList.Add(new MLRebarRecord(6, add, no, MainRebarDB, NumAddL - NumAddLC, eShapeType.ML, aa, bb, cc, rr));
                    if (no == "a")
                        no = "b";
                    else if (no == "b")
                        no = "c";
                    else if (no == "c")
                        no = "d";
                    else if (no == "d")
                        no = "e";
                    else if (no == "e")
                        no = "f";
                    else if (no == "f")
                        no = "g";
                    else
                        no = "h";
                }
               
            }
            #endregion

            #region UBlot数量计算
            if (isDiv)
                UAN1N2 = NumMainAll * 8;
            else
                UAN1N2 = NumMainAll * 4;
            if (isDiv)
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 8;
            }
            else
            {
                UboltList.UBoltNum[MainRebarDB] += NumMainAll * 4;
            }
            #endregion
        }
    }

}
